<?php

namespace Home\Controller;

use OT\DataDictionary;

/**
 * 推广页面
 *
 */
class GeneralizeController extends HomeController
{
    //推广页面1
    public function generalize_index()
    {
        srand((float)microtime() * 10000000);
        $url_arr = array(
            '1' => 'a',
            '2' => 'b',
            '3' => 'c',
            '4' => 'd',
            '5' => 'e',
        );
        $url = array_rand($url_arr, 1);

        //获取网站的域名
        $urls = 'http://' . $_SERVER['HTTP_HOST'] . '/index.php/Home/Generalize/';

        //循环中调用
        switch ($url) {
            case "1":
                //$this->generalize_1();
                $url_data = $urls . 'generalize_1/generalize_1.html';
                header("Location: $url_data");
                break;
            case "2":
                //$this->generalize_2();
                $url_data = $urls . 'generalize_2/generalize_2.html';
                header("Location: $url_data");
                break;
            case "3":
                //$this->generalize_3();
                $url_data = $urls . 'generalize_3/generalize_3.html';
                header("Location: $url_data");
                break;
            case "4":
                //$this->generalize_4();
                $url_data = $urls . 'generalize_4/generalize_4.html';
                header("Location: $url_data");
                break;
            case "5":
                //$this->generalize_5();
                $url_data = $urls . 'generalize_5/generalize_5.html';
                header("Location: $url_data");
                break;
        }

    }

    //推广页面1
    public function generalize_1()
    {
        //获取完整的url
        /*header("Content-Type: text/html; charset=utf8");*/

        $visit_url = 'http://' . $_SERVER['HTTP_HOST'] . '/index.php/Home/Generalize/generalize_1/generalize_1.html';
        $this->assign('visit_url', $visit_url);
        $this->display("generalize_1");
    }

    //推广页面2
    public function generalize_2()
    {
        //$visit_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
        $visit_url = 'http://' . $_SERVER['HTTP_HOST'] . '/index.php/Home/Generalize/generalize_2/generalize_2.html';
        $this->assign('visit_url', $visit_url);
        $this->display("generalize_2");
    }

    //推广页面3
    public function generalize_3()
    {
        $visit_url = 'http://' . $_SERVER['HTTP_HOST'] . '/index.php/Home/Generalize/generalize_3/generalize_3.html';
        $this->assign('visit_url', $visit_url);
        $this->display("generalize_3");
    }

    //推广页面4
    public function generalize_4()
    {
        $visit_url = 'http://' . $_SERVER['HTTP_HOST'] . '/index.php/Home/Generalize/generalize_4/generalize_4.html';
        $this->assign('visit_url', $visit_url);
        $this->display("generalize_4");
    }

    //推广页面5
    public function generalize_5()
    {
        $visit_url = 'http://' . $_SERVER['HTTP_HOST'] . '/index.php/Home/Generalize/generalize_5/generalize_5.html';
        $this->assign('visit_url', $visit_url);
        $this->display("generalize_5");
    }

    //获取网站的地址和ip
    public function addip_url()
    {
        $visit_url = I('visit_url');
        $ip = get_client_ip();
        $time = date('Y-m-d H:i:s', time());

        $MemberMessaged_model = D('MemberMessaged');
        $data = array(
            'visit_url' => $visit_url,
            'visit_ip' => $ip,
            'add_time' => $time,
            'hit' => 1,
            'web_state' => 2,
        );

        //查询当前的ip是否存在
        $visit_ip_s = $MemberMessaged_model->info_data(array('visit_ip' => $ip, 'visit_url' => $visit_url, 'web_state' => 2));

        if (empty($visit_ip_s)) {
            $re = $MemberMessaged_model->addData($data);
        }
        //跳转页面—国外
        header("Location: https://chat.whatsapp.com/Dd96nLBdKbAB6RiMrVG6kj");
        //header("Location: https://chat.whatsapp.com/AmGNPQz39w30gzh2oLWIMr");
        //header("Location: https://chat.whatsapp.com/2qyfjd3HTUZAPyvKbAeAa5");
        //$this->success('点击成功', 'index.php/home/Generalize/index');

    }

    /*
     * 添加用户的提交信息
     * */
    public function addMessaged()
    {
        $name = I('name');
        $email = I('email');
        $phone_number = I('phone_number');
        $visit_url = I('visit_url');
        $ip = get_client_ip();
        $time = date('Y-m-d H:i:s', time());

        $MemberMessaged_model = D('MemberMessaged');
        $data = array(
            'name' => $name,
            'email' => $email,
            'phone_number' => $phone_number,
            'visit_url' => $visit_url,
            'visit_ip' => $ip,
            'add_time' => $time,
            'web_state' => 1,
        );

        //查询当前的ip是否存在
        $where = array(
            'name' => $name,
            'email' => $email,
            'phone_number' => $phone_number,
            'visit_url' => $visit_url,
        );
        $where_data = $MemberMessaged_model->info_data($where);
        if (empty($where_data)) {
            if(!empty($visit_url)){
                $re = $MemberMessaged_model->addData($data);
            }
        }
        echo "<script>alert('Register berhasil');window.history.go(-1)</script></script>";
    }

}